tests/str: Rework invocation
authorColin Walters <walters@verbum.org>
Fri, 9 Mar 2018 18:26:07 +0000 (13:26 -0500)
committerAtomic Bot <atomic-devel@projectatomic.io>
Fri, 16 Mar 2018 13:26:22 +0000 (13:26 +0000)
Let's make our `run.sh` generically support any playbook. This is prep for
writing further tests in Ansible. Along with that, rework the Ansible so that
`tests.yml` is a playbook, and then the other bits are just task lists. It's
easier to read.

I also started to add a `use_git_build` variable with the idea that we'll be
able to run these same tests against an upstream image by setting that variable
off.

Closes: #1493
Approved by: jlebon

.papr.yml
tests/fedora-str/overlay-git.yml
tests/fedora-str/playbook-run.sh [new file with mode: 0755]
tests/fedora-str/run.sh [deleted file]
tests/fedora-str/sysinstall-tests.yml
tests/fedora-str/tests.yml

index bb84e689d131c6c92ebe31e9f39466765f2a5fca..da06fa9589462d7436e9299449eaceb5631cbcf1 100644 (file)
--- a/.papr.yml
+++ b/.papr.yml
@@ -15,7 +15,7 @@ tests:
   - ./tests/fedora-str/provision.sh
   # TODO: enhance papr to have caching, a bit like https://docs.travis-ci.com/user/caching/
   - curl -Lo fedora-atomic-host.qcow2 https://getfedora.org/atomic_qcow2_latest
-  - env "TEST_SUBJECTS=$(pwd)/fedora-atomic-host.qcow2" ./tests/fedora-str/run.sh
+  - env "TEST_SUBJECTS=$(pwd)/fedora-atomic-host.qcow2" ./tests/fedora-str/playbook-run.sh tests/fedora-str/tests.yml
 
 artifacts:
   - tests/fedora-str/artifacts/fedora-atomic-host.qcow2.log
index 41d128463ecff635b571f959132cffd5c3a5210d..dc0623db8c49aed855eb383108230f6e958fec2b 100644 (file)
@@ -1,31 +1,27 @@
----
-- hosts: localhost
-  tags:
-  - atomic
-  remote_user: root
-  tasks:
-  - command: ostree --version
-    changed_when: False
-    register: ostree_orig_version
-  - set_fact:
-      ostree_orig_version_yaml: "{{ ostree_orig_version.stdout | from_yaml }}"
-  - name: Copy locally built RPMs
-    synchronize: src=x86_64/ dest=/root/x86_64/ archive=yes
-  - shell: ostree admin unlock || true
-  # Install the RPMs we already have.  For the test suite we use rpm2cpio
-  # since it depends on libsoup, but we're not using that yet for the sysinstalled tests
-  - shell: >
-      /usr/bin/rpm -Fvh /root/x86_64/*.rpm && \
-      cd / && rpm2cpio /root/x86_64/ostree-tests-2*.rpm | cpio -div
-  - command: ostree --version
-    register: ostree_new_version
-  - set_fact:
-      ostree_new_version_yaml: "{{ ostree_new_version.stdout | from_yaml }}"
-  - name: "Fail if we didn't change the ostree version"
-    when: ostree_orig_version_yaml['libostree']['Git'] == ostree_new_version_yaml['libostree']['Git']
-    fail:
-      msg: "Failed to change ostree version"
+# Run "admin unlock" and add locally built RPMs, then
+# copy the whole tests/ directory into the VM.
+- command: ostree --version
+  changed_when: False
+  register: ostree_orig_version
+- set_fact:
+    ostree_orig_version_yaml: "{{ ostree_orig_version.stdout | from_yaml }}"
+- name: Copy locally built RPMs
+  synchronize: src=x86_64/ dest=/root/x86_64/ archive=yes
+- shell: ostree admin unlock || true
+# Install the RPMs we already have.  For the test suite we use rpm2cpio
+# since it depends on libsoup, but we're not using that yet for the sysinstalled tests
+- shell: >
+    /usr/bin/rpm -Fvh /root/x86_64/*.rpm && \
+    cd / && rpm2cpio /root/x86_64/ostree-tests-2*.rpm | cpio -div
+- command: ostree --version
+  register: ostree_new_version
+- set_fact:
+    ostree_new_version_yaml: "{{ ostree_new_version.stdout | from_yaml }}"
+- name: "Fail if we didn't change the ostree version"
+  when: ostree_orig_version_yaml['libostree']['Git'] == ostree_new_version_yaml['libostree']['Git']
+  fail:
+    msg: "Failed to change ostree version"
 
-  # Next copy all of the tests/ directory
-  - name: Copy test data
-    synchronize: src=../../ dest=/root/tests/ archive=yes
+# Next copy all of the tests/ directory
+- name: Copy test data
+  synchronize: src=../../ dest=/root/tests/ archive=yes
diff --git a/tests/fedora-str/playbook-run.sh b/tests/fedora-str/playbook-run.sh
new file mode 100755 (executable)
index 0000000..1499d08
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/bash
+# A thin wrapper for ansible-playbook which has a nice check for
+# TEST_SUBJECTS being set.
+set -xeuo pipefail
+
+# https://fedoraproject.org/wiki/CI/Tests
+if test -z "${TEST_SUBJECTS:-}"; then
+    cat <<EOF
+
+error: TEST_SUBJECTS must be set; e.g.:
+
+  curl -Lo fedora-atomic-host.qcow2 'https://getfedora.org/atomic_qcow2_latest'
+  export TEST_SUBJECTS=\$(pwd)/fedora-atomic-host.qcow2
+
+If you're doing interactive development, we recommend caching the qcow2
+somewhere persistent.
+EOF
+    exit 1
+fi
+ls -al ${TEST_SUBJECTS}
+
+export ANSIBLE_INVENTORY=${ANSIBLE_INVENTORY:-$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory)}
+ls -al /dev/kvm
+exec ansible-playbook --tags=atomic "$@"
diff --git a/tests/fedora-str/run.sh b/tests/fedora-str/run.sh
deleted file mode 100755 (executable)
index 8714a85..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/usr/bin/bash
-set -xeuo pipefail
-
-dn=$(cd $(dirname $0) && pwd)
-cd ${dn}
-
-# https://fedoraproject.org/wiki/CI/Tests
-if test -z "${TEST_SUBJECTS:-}"; then
-    cat <<EOF
-
-error: TEST_SUBJECTS must be set; e.g.:
-
-  curl -Lo fedora-atomic-host.qcow2 'https://getfedora.org/atomic_qcow2_latest'
-  export TEST_SUBJECTS=\$(pwd)/fedora-atomic-host.qcow2
-
-If you're doing interactive development, we recommend caching the qcow2
-somewhere persistent.
-EOF
-    exit 1
-fi
-ls -al ${TEST_SUBJECTS}
-
-export ANSIBLE_INVENTORY=${ANSIBLE_INVENTORY:-$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory)}
-ls -al /dev/kvm
-ansible-playbook --tags=atomic tests.yml
index 366a7a5779c870c1b04c60d26fc54d9a73a67b66..7990e1f7154955258ad7e544336ec89d9d36b3f5 100644 (file)
@@ -1,20 +1,17 @@
----
-- hosts: localhost
-  tags:
-  - atomic
-  remote_user: root
-  tasks:
-  # Down the line perhaps do each log file separately?
-  - name: Run sysinstalled tests
-    shell: /root/tests/installed/run.sh &> /root/installed-tests.log
-    register: sysinstalled_result
-    failed_when: False
-  - name: Fetch sysinstalled results
-    fetch:
-      src: /root/installed-tests.log
-      dest: artifacts/installed-tests.log
-      flat: yes
-  - name: Assert that sysinstalled tests succeeded
-    when: sysinstalled_result.rc != 0
-    fail:
-      msg: "sysinstalled tests failed"
+# Run the system installed tests
+- import_tasks: overlay-git.yml
+  when: use_git_build
+# Down the line perhaps do each log file separately?
+- name: Run sysinstalled tests
+  shell: /root/tests/installed/run.sh &> /root/installed-tests.log
+  register: sysinstalled_result
+  failed_when: False
+- name: Fetch sysinstalled results
+  fetch:
+    src: /root/installed-tests.log
+    dest: artifacts/installed-tests.log
+    flat: yes
+- name: Assert that sysinstalled tests succeeded
+  when: sysinstalled_result.rc != 0
+  fail:
+    msg: "sysinstalled tests failed"
index 7a78adb371793fca44fd7a199775625fe65198f8..0c60fd07a240cecc7c1afacd323e4f51da19a400 100644 (file)
@@ -1,2 +1,10 @@
-- include: overlay-git.yml
-- include: sysinstall-tests.yml
+# This entrypoint right now just runs the sysinstalled-tests.
+---
+- hosts: localhost
+  tags:
+  - atomic
+  remote_user: root
+  vars:
+    use_git_build: True
+  tasks:
+    - import_tasks: sysinstall-tests.yml